﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WebLog
{
    static class WebLogStatusChangeHandle
    {
        static List<Action<EvnetWebLogStatusChange>> Observers = new List<Action<EvnetWebLogStatusChange>>();
        public static void Add(Action<EvnetWebLogStatusChange> changeCall)
        {
            if (changeCall != null)
                Observers.Add(changeCall);
        }
        public static void Remove(Action<EvnetWebLogStatusChange> changeCall)
        {
            Observers.Remove(changeCall);
        }
        public static void ChangeStatusPush(EvnetWebLogStatusChange evnetWebLogStatus)
        {
            if (Observers?.Count > 0)
                foreach (var observer in Observers)
                    observer(evnetWebLogStatus);
        }
        public static void ChangeStatusPush(WebLogStatus? oldStatus, WebLogStatus? newStatus, object source = null, DateTime? time = null)
        {
            ChangeStatusPush(new EvnetWebLogStatusChange
            {
                oldStatus = oldStatus,
                newStatus = newStatus,
                Source = source,
                Time = time ?? DateTime.Now
            });
        }
    }
}
